package com.dys.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @className: com.dys.servlet.ServletCookie
 * @description: 响应Cookie
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/09/20 20:54
 */
@WebServlet(urlPatterns = "/servlet01.do")
public class ServletCookie extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("进入ServletCookie的service方法......");
        // 通过响应对象,向浏览器响应一些Cookie
        // 状态Cookie,重启浏览器立即清除Cookie
        Cookie c1 = new Cookie("age", "10");
        // 持久化Cookie 让浏览器保留1分钟
        Cookie c2 = new Cookie("sex", "男");
        // 秒钟  持久化Cookie 让浏览器保留1分钟
        c2.setMaxAge(60);
        resp.addCookie(c1);
        resp.addCookie(c2);
    }
}
